import hashlib
import jwt
import datetime
from django.conf import settings
def password_encrypt(pwd):
    md5 = hashlib.md5()  # 2，实例化md5() 方法
    md5.update(pwd.encode())  # 3，对字符串的字节类型加密
    result = md5.hexdigest()  # 4，加密
    return result


# get_token函数
def get_token(payload, timeout):
    salt = settings.SECRET_KEY
    headers = {
        "typ": "jwt_",
        "alg": "HS256",
    }
    payload["exp"] = datetime.datetime.utcnow() + datetime.timedelta(minutes=timeout)
    token = jwt.encode(payload=payload, key=salt, headers=headers).decode("utf-8")
    return token